using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Shop_Member_Shop_ManageFShopClass : Member, IRequiresSessionState
{
	protected TextBox TxtF_ShopClassName;
	protected Label LabErro;
	protected TextBox TxtF_ShopClassRemark;
	protected Label UpdateText;
	protected Button ButUpdate;
	protected Button ButADD;
	protected RequiredFieldValidator Ref1;
	protected TextBox TXTPROCLASSID;
	protected GridView GridView1;
	protected ObjectDataSource ObjectDataSource1;
	private int F_ShopClassID = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (base.Request["F_ShopClassID"] != null)
			{
				this.F_ShopClassID = int.Parse(base.Request["F_ShopClassID"].ToString());
				Shop_FShopClass shop_FShopClass = new Shop_FShopClass();
				DataRow dataRow = shop_FShopClass.GetFShopClassByFShopClassID(this.F_ShopClassID).Rows[0];
				this.TxtF_ShopClassName.Text = dataRow["F_ShopClassName"].ToString();
				this.TxtF_ShopClassRemark.Text = dataRow["F_ShopClassRemark"].ToString();
				this.TXTPROCLASSID.Text = this.F_ShopClassID.ToString();
				this.ButADD.Visible = false;
				this.ButUpdate.Visible = true;
			}
			else
			{
				this.ButADD.Visible = true;
				this.ButUpdate.Visible = false;
			}
		}
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			Shop_MyFavourite shop_MyFavourite = new Shop_MyFavourite();
			gridViewRow.Cells[2].Text = shop_MyFavourite.GetShopCountByClassID(int.Parse(Fetch.GetCookies("Howave_UserID")), int.Parse(gridViewRow.Cells[0].Text)).ToString();
		}
	}
	protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
	{
		Shop_FShopClass shop_FShopClass = new Shop_FShopClass();
		shop_FShopClass.DeleteFShopClass(int.Parse(this.GridView1.SelectedRow.Cells[0].Text.ToString()));
		this.ObjectDataSource1.Update();
	}
	protected void ButUpdate_Click(object sender, EventArgs e)
	{
		if (this.TxtF_ShopClassName.Text.Length > 6)
		{
			this.LabErro.Text = "类别名称不能超过6个字";
		}
		else
		{
			if (this.TxtF_ShopClassRemark.Text.Length > 50)
			{
				this.UpdateText.Text = "备注内容不能超过50个字";
			}
			else
			{
				Shop_FShopClass shop_FShopClass = new Shop_FShopClass();
				shop_FShopClass.UpdateFShopClass(this.TxtF_ShopClassName.Text, this.TxtF_ShopClassRemark.Text, int.Parse(this.TXTPROCLASSID.Text));
				this.ObjectDataSource1.Update();
				this.LabErro.Text = "";
				base.Response.Redirect("Shop_MyFavourite.aspx?tag=1");
			}
		}
	}
	protected void ButADD_Click(object sender, EventArgs e)
	{
		if (this.TxtF_ShopClassName.Text.Length > 6)
		{
			this.LabErro.Text = "类别分类不能超过6个字!";
		}
		else
		{
			Shop_FShopClass shop_FShopClass = new Shop_FShopClass();
			if (shop_FShopClass.GetFShopClassByUserID(int.Parse(Fetch.GetCookies("Howave_UserID"))).Rows.Count >= 5)
			{
				this.LabErro.Text = "类别最多只能添加5种";
			}
			else
			{
				shop_FShopClass.InsertFShopClass(this.TxtF_ShopClassName.Text, int.Parse(Fetch.GetCookies("Howave_UserID")), this.TxtF_ShopClassRemark.Text);
				this.ObjectDataSource1.Update();
				this.LabErro.Text = "";
				base.Response.Redirect("Shop_MyFavourite.aspx?tag=1");
			}
		}
	}
}
